<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Myexception extends Exception{

	private $CI;
	function __construct()
	{
		parent::__construct();
		$this->CI = &get_instance();
	}

	/**
	 * @desc 	异常处理函数
	 * @parm 	object $e 异常对象
	 */
	public static function exceptionHandler($e){
		$file 	= $e->getFile();
		$line 	= $e->getLine();
		$code 	= $e->getCode();
		$message= $e->getMessage();
		$CI = &get_instance();
		$CI->load->library('api_log');
		$CI->api_log->add('ERROR','['.$code.']:'.$message,array('file'=>$file,'line'=>$line));
	}

	/**
	 * @desc 	错误处理函数
	 *
	 */
	public static function errorHandler($errno,$errstr,$errfile,$errline){
		self::exceptionHandler(new ErrorException($errstr,$errno,0,$errfile,$errline));
	}

	/**
	 *
	 *
	 */
	public static function shutdownHandler(){
		$error = error_get_last();
		if($error){
			self::exceptionHandler(new ErrorException($error['message'],$error['type'],0,$error['file'],$error['line']));
		}
	}
}